package wangjg.test.udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UDPServer {
	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		byte[] buf = new byte[20];
		DatagramSocket ds = new DatagramSocket(6001);
		DatagramPacket dp = new DatagramPacket(buf, buf.length);
//		ds.send(new DatagramPacket(buf, buf.length,new java.net.InetSocketAddress("210.13.116.210", 6001)));//?sendto wlan
		System.out.println("listen...");
		while (true) {
			ds.receive(dp);
			System.out.println(
				"Port=" + dp.getPort() + ",Address="+ dp.getAddress() 
				+ ",Data=\"" + new String(dp.getData(),dp.getOffset(),dp.getLength()) 
				+ "\",Length="+ dp.getLength() + ",Offset=" + dp.getOffset()
			);
		}
	}
}
